"use client"
import React, { useState,useEffect } from 'react';
import {
  Button,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Radio,
  Select,
  Switch,
  TreeSelect,
} from 'antd';

import * as API from '../../axios/http'
import { log } from 'console';

const Myform = (props:any) => {
 

  const [form] = Form.useForm();
  useEffect(()=>{
    if(props.title =="编辑"){
      form.setFieldsValue(props.itemObj)
    }
  },[])



  const onFinish = (values:any) => {
    if (props.title == "添加") {
      const obj = {
        id: new Date().getTime(),
        ...values,
        date: new Date(new Date().getTime()).toLocaleString(),
      }
      API.http_addlzy(obj).then(() => {
        props.setdata(obj)
      })
      
    }else{
      const obj = {
        ...props.itemObj,
        ...values
      }
      console.log(obj);
      
      API.http_editLzy(obj).then(() => {
        props.setdata(obj) 
      })
    }
  }

  return (
    <Form
      form={form}
      onFinish={onFinish}
      style={{ maxWidth: 600 }}
    >



      <Form.Item label="订单标题" name="title">
        <Input />
      </Form.Item>
      <Form.Item label="客户名称" name="name">
        <Input />
      </Form.Item>
      <Form.Item label="回款其次" name="hui">
        <Select
          style={{ width: "200px", marginLeft: "20px" }}
          options={[
            { value: '第一期(共4期)', label: '第一期(共4期)' },
            { value: '第二期(共4期)', label: '第二期(共4期)' },
            { value: '第三期(共4期)', label: '第三期(共4期)' },
            { value: '第四期(共4期)', label: '第四期(共4期)' },

          ]}
          placeholder="回款其次"
        />
      </Form.Item>
      <Form.Item label="订单总金额" name="moery">
        <InputNumber min={1} />
      </Form.Item>
      <Form.Item label="已回款金额" name="yihui">
        <InputNumber min={1} />
      </Form.Item>
      {/* <Form.Item label="签单日期" name="date">
        <DatePicker />
      </Form.Item> */}
      <Form.Item label="回款状态" name="status">
        <Select
          style={{ width: "200px", marginLeft: "20px" }}
          options={[
            { value: '已完成', label: '已完成' },
            { value: '未完成', label: '未完成' },
            { value: '已逾期', label: '已逾期' },
          ]}
          placeholder="回款状态"
        />
      </Form.Item>


      <Form.Item label={null}>
        <Button type="primary" htmlType="submit" onClick={()=>{
          props.handleOk()
        }}>
          下一步
        </Button>
      </Form.Item>
    </Form>
  );
};

export default Myform;